<!--
 * @Descripttion: 
 * @version: 1.0
 * @Author: 任静
 * @Date: 2020-11-12 20:39:08
 * @LastEditors: 任静
 * @LastEditTime: 2020-11-13 21:15:21
-->
<template>
  <div class="search">
    <van-nav-bar
      title="搜索"
      left-text="返回"
      left-arrow
      @click-left="toBack"
    />

    <van-search v-model="value" shape="round" placeholder="value" />
    <div class="rank">
      <h3>排名</h3>
      <div class="list" v-if="rankList.length > 0">
        <!-- {{ rankList ? rankList : "111" }} -->
        <dl v-for="item in rankList" :key="item.id">
          <dt><img :src="item.image" alt="" @click="goDetail(item)" /></dt>
          <dd>{{ item.name }}</dd>
        </dl>
      </div>
      <!-- <div class="empty" v-else>
        <van-empty image="search" description="搜索内容排行为空" />
      </div> -->
    </div>
    <div class="content">
      <h3>内容</h3>
      <div class="list">
        <dl v-for="item in articleList" :key="item.id">
          <dt>
            <video controls :poster="item.image">
              <source :src="item.video" type="" />
            </video>
          </dt>
          <dd>
            <p>{{ item.title }}</p>
            <p>
              <span>
                <img :src="item.avatar" alt="" /> {{ item.nickname }}
              </span>
              <span>推荐值: {{ item.score }} </span>
            </p>
          </dd>
        </dl>
      </div>
          <div class="empty" v-if="articleList.length<0">
        <van-empty image="search" description="搜索内容排行为空" />
      </div>
      <!-- {{ articleList }} -->
    </div>
  </div>
</template>
<script>
import { defineComponent, computed, ref, reactive } from "vue";
import { useStore } from "vuex";
import { useRouter, useRoute } from "vue-router";
export default defineComponent({
  setup(props, context) {
    //搜索输入的关键字
    let value = ref("");
    let router = useRouter();
    let route = useRoute();
    let store = useStore();
    function toBack() {
      router.go(-1);
    }
    console.log(route.query);
    value = route.query.searchkey;
    store.dispatch("search/getSearchList", {
      mid: 0,
      keyword: route.query.searchkey,
    });
    store.dispatch("search/getSearchTipList", {
      keyword: route.query.searchkey,
    });
    function goDetail(item) {
      let id = item.id;
      router.push({ path: "/detail", query: { id } });
    }
    return {
      value,
      toBack,
      articleList: computed(() => store.state.search.articleList),
      rankList: computed(() => store.state.search.rankList),
      goDetail,
    };
  },
});
</script>
<style lang="scss" scoped>
.search {
  width: 100%;
  height: 100%;
  font-size: 0.14rem;
  h2 {
    display: flex;
    height: 0.6rem;
    font-size: 0.16rem;
    justify-content: space-around;
    align-items: center;
    border-bottom: 1px solid #ccc;
  }

  .rank {
    width: 100%;
    min-height: 1rem;
    box-sizing: border-box;
    padding: 0.2rem;
    .list {
      display: flex;
      width: 100%;
      flex-wrap: wrap;
      box-sizing: border-box;
      margin-top: 10px;
      dl {
        width: 25%;
        text-align: center;

        img {
          width: 70%;
        }
      }
    }
  }
  .content {
    width: 100%;
    min-height: 1rem;
    box-sizing: border-box;
    padding: 0.2rem;
    margin-top: 15px;
    .list {
      width: 98%;
      display: flex;
      flex-wrap: wrap;
      margin: 0 auto;

      dl {
        width: 48%;
        padding-left: 5px;
        dt {
          video {
            width: 100%;
            height: 120px;
          }
        }
        dd {
          p {
            display: flex;
            justify-content: space-between;
            height: 30px;
            img {
              width: 20px;
              height: 20px;
              border-radius: 50%;
            }
          }
        }
      }
    }
  }
}
.empty {
  height: 100px;
  margin: 15px auto;
  .van-empty {
    width: 100%;
    height: 40px;
    .custom-image .van-empty__image {
      width: 100%;
      height: 40px;
    }
  }
}
</style>